package com.zj.processors;

import com.zj.bean.TableInfo;
import com.zj.job.CodeSnippetJob;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.springframework.stereotype.Component;

import java.io.StringWriter;

@Component
public class ServiceImplProcessor extends BaseProcessor implements TemplateProcessor{


    @Override
    public String getName() {
        return "serviceImpl";
    }

    @Override
    public String process(TableInfo tableInfo, CodeSnippetJob codeSnippetJob) {
        Template vmTemplate = loadTemplate("template-code-snippet/serviceImpl.vm");

        String modelName=convertDomainName(tableInfo.getTableName());
        String modelAsParam = lowFirstChar(modelName);

        VelocityContext context = new VelocityContext();
        context.put("modelName",modelName);
        context.put("modelAsParam",modelAsParam);

        StringWriter stringWriter = new StringWriter();
        vmTemplate.merge(context,stringWriter);
        codeSnippetJob.log(stringWriter.toString());

        return "ok";
    }
}
